home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / network / qlst14.zip / QLST.CPP < prev    next >
C/C++ Source or Header  |  1992-10-29  |  11KB  |  513 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4. #include <dir.h>
  5. #include <string.h>
  6. #include <mem.h>
  7. #include <stdlib.h>
  8.  
  9. typedef unsigned char BYTE;
  10. typedef unsigned int  WORD;
  11. typedef unsigned long LONG;
  12.  
  13. #define zap(a)              {memset ( &a, NULL, sizeof(a));}
  14. #define size(a)             {a.Length=sizeof(a)-2;}
  15.  
  16. struct scanBindReq {
  17.     WORD    Length;
  18.     BYTE    Function;
  19.     LONG    LastObjectID;
  20.     WORD    ObjectType;
  21.     BYTE    ObjectNameLength;
  22.     BYTE    ObjectName[48];
  23.     };
  24.  
  25. struct scanBindRep {
  26.     WORD    Length;
  27.     LONG    ObjectID;
  28.     WORD    ObjectType;
  29.     BYTE    ObjectName[48];
  30.     BYTE    ObjectFlag;
  31.     BYTE    ObjectSecurity;
  32.     BYTE    ObjectHasProperties;
  33.     };
  34.  
  35. struct readPropValueReq {
  36.     WORD    Length;
  37.     BYTE    Function;
  38.     WORD    ObjectType;
  39.     BYTE    ObjectNameLength;
  40.     BYTE    ObjectName[48];
  41.     BYTE    SegmentNumber;
  42.     BYTE    PropertyNameLength;
  43.     BYTE    PropertyName[16];
  44.     };
  45.  
  46. struct readPropValueRep {
  47.     WORD    Length;
  48.     BYTE    PropertyValue[128];
  49.     BYTE    MoreSegments;
  50.     BYTE    PropertyFlags;
  51.     };
  52.  
  53. struct readQueueStatReq {
  54.     WORD    Length;
  55.     BYTE    Function;
  56.     LONG    ObjectID;
  57.     };
  58.  
  59. struct readQueueStatRep {
  60.     WORD    Length;
  61.     LONG    ObjectID;
  62.     BYTE    QueueStatus;
  63.     BYTE    NumberOfJobs;
  64.     BYTE    NumberOfServers;
  65.     LONG    ServerID[25];
  66.     BYTE    ServerStation[25];
  67.     BYTE    MaxServers;
  68.     };
  69.  
  70. struct getBindObjNameReq {
  71.     WORD    Length;
  72.     BYTE    Function;
  73.     LONG    ObjectID;
  74.     };
  75.  
  76. struct getBindObjNameRep {
  77.     WORD    Length;
  78.     LONG    ObjectID;
  79.     WORD    ObjectType;
  80.     BYTE    ObjectName[48];
  81.     };
  82.  
  83. struct getJobListReq {
  84.     WORD    Length;
  85.     BYTE    Function;
  86.     LONG    QueueID;
  87.     };
  88.  
  89. struct getJobListRep {
  90.     WORD    Length;
  91.     WORD    JobCount;
  92.     WORD    JobList[250];
  93.     };
  94.  
  95. struct getJobReq {
  96.     WORD    Length;
  97.     BYTE    Function;
  98.     LONG    QueueID;
  99.     WORD    JobNum;
  100.     };
  101.  
  102. struct getJobRep {
  103.     WORD    Length;
  104.     BYTE    ClientStation;
  105.     BYTE    ClientTaskNumber;
  106.     LONG    ClientIDNumber;
  107.     LONG    TargerServerIDNumber;
  108.     BYTE    TargerExecutionTime[6];
  109.     BYTE    JobEntryTime[6];
  110.     WORD    JobNumber;
  111.     WORD    JobType;
  112.     BYTE    JobPosition;
  113.     BYTE    JobControllFlags;
  114.     BYTE    JobFileName[14];
  115.     BYTE    JobFileHandle[6];
  116.     BYTE    ServerStation;
  117.     BYTE    ServerTaskNumber;
  118.     LONG    ServerIDNumber;
  119.     BYTE    TextJobDescription[50];
  120.     BYTE    ClientRecordAreaVersion;
  121.     WORD    TabSize;
  122.     WORD    NumberOfCopies;
  123.     BYTE    ControllFlags; // WORD
  124.     WORD    MaxLines;
  125.     WORD    MaxCharacters;
  126.     BYTE    FormName[16];
  127.     BYTE    Dummy[6]; // Reserved
  128.     BYTE    BannerName[13]; // 14
  129.     BYTE    FileNameOnBanner[13];
  130.     BYTE    FileNameInHeader[14]; // 16
  131.     BYTE    DirPath[80];
  132.     };
  133.  
  134. struct getFileSizeReq {
  135.     WORD    Length;
  136.     BYTE    Function;
  137.     LONG    QueueID;
  138.     WORD    JobNum;
  139.     };
  140.  
  141. struct getFileSizeRep {
  142.     WORD    Length;
  143.     LONG    QueueID;
  144.     WORD    JobNum;
  145.     LONG    FileSize;
  146.     };
  147.  
  148. struct QueueEntry {
  149.     int  Ready;
  150.     int  NumOfJobs;
  151.     int  NumOfServers;
  152.     LONG QueueID;
  153.     char QueueName[48];
  154.     LONG PrintID;
  155.     char PrintName[48];
  156.     char Location[100];
  157.     };
  158.  
  159. char ProgName[]="Queue List";
  160. int VerMaj=1;
  161. int VerMin=3;
  162. int QueueCount=0;
  163. #define MaxEntry 100
  164. struct QueueEntry QueueList[MaxEntry];
  165. int AnyJob=0;
  166.  
  167. char *qstat[]={"<Offline>","",};
  168.  
  169. int API_E3(void *Request, void *Reply)
  170. {
  171.     _SI=(unsigned)Request;
  172.     _DI=(unsigned)Reply;
  173.     _ES=_DS;
  174.     _AH=0xE3;
  175.     geninterrupt(0x21);
  176.     return(_AL);
  177. }
  178.  
  179. void PrintError(int ern)
  180. {
  181.     switch (ern)
  182.     {
  183.         case 0x00: printf("Success\n");                  break;
  184.         case 0x96: printf("Server Out Of Memory\n");     break;
  185.         case 0x9C: printf("Invalid Path\n");             break;
  186.         case 0xD0: printf("Q Error\n");                  break;
  187.         case 0xD1: printf("No Queue\n");                 break;
  188.         case 0xD2: printf("No Q Server\n");              break;
  189.         case 0xD3: printf("No Q Rights\n");              break;
  190.         case 0xD5: printf("No Q Job\n");                 break;
  191.         case 0xEC: printf("No Such Segment\n");          break;
  192.         case 0xEF: printf("Invalid name\n");             break;
  193.         case 0xF0: printf("Wildcard Not Allowed\n");     break;
  194.         case 0xF1: printf("Invalid Bindary Security\n"); break;
  195.         case 0xFB: printf("No Such Property\n");         break;
  196.         case 0xFC: printf("No Such Object\n");           break;
  197.         case 0xFE: printf("Server Bindary Locked\n");    break;
  198.         case 0xFF: printf("Bindary Failure\n");          break;
  199.         default:   printf("Unknown error #%2x#2\n",ern); break;
  200.     }
  201. }
  202.  
  203. WORD swapw(WORD x)
  204. {
  205.     union
  206.     {
  207.         WORD w;
  208.         BYTE b[2];
  209.     } U;
  210.     BYTE t;
  211.  
  212.     U.w=x;
  213.     t=U.b[0];
  214.     U.b[0]=U.b[1];
  215.     U.b[1]=t;
  216.  
  217.     return (U.w);
  218. }
  219.  
  220. LONG swapl(LONG x)
  221. {
  222.     union
  223.     {
  224.         LONG l;
  225.         WORD w[2];
  226.     } U;
  227.     WORD t;
  228.  
  229.     U.l=x;
  230.     t=swapw(U.w[0]);
  231.     U.w[0]=swapw(U.w[1]);
  232.     U.w[1]=t;
  233.     return (U.l);
  234. }
  235.  
  236. void GetQueueList()
  237. {
  238.     struct scanBindReq Request;
  239.     struct scanBindRep Reply;
  240.     int    result;
  241.  
  242.     zap(Request); size(Request);
  243.     zap(Reply);   size(Reply);
  244.     Request.Function=0x37; // p 146
  245.     Request.LastObjectID=0xFFFFFFFF;
  246.     Request.ObjectType=swapw(0x0003); // queue
  247.     Request.ObjectNameLength=1;
  248.     strcpy(Request.ObjectName,"*");
  249.  
  250.     result=API_E3(&Request,&Reply);
  251.  
  252.     while (result==0)
  253.     {
  254.         zap(QueueList[QueueCount]);
  255.         QueueList[QueueCount].QueueID=Reply.ObjectID;
  256.         strcpy(QueueList[QueueCount].QueueName,Reply.ObjectName);
  257.         if (QueueCount++>MaxEntry) exit(1);
  258.         Request.LastObjectID=Reply.ObjectID;
  259.         result=API_E3(&Request,&Reply);
  260.     }
  261.     if (result!=0xFC) PrintError(result);
  262. }
  263.  
  264. LONG GetDefaultPrinter(char *QueueName)
  265. {
  266.     struct readPropValueReq Request;
  267.     struct readPropValueRep Reply;
  268.     int    result;
  269.  
  270.     union {
  271.         char s[4];
  272.         LONG l;
  273.     } PServer;
  274.  
  275.     zap(Request); size(Request);
  276.     zap(Reply);   size(Reply);
  277.     Request.Function=0x3D; // p 160
  278.     Request.ObjectType=swapw(0x0003); // Queue
  279.     Request.ObjectNameLength=sizeof(Request.ObjectName);
  280.     strcpy(Request.ObjectName,QueueName);
  281.     Request.SegmentNumber=1;
  282.     Request.PropertyNameLength=9;
  283.     strcpy(Request.PropertyName,"Q_SERVERS");
  284.  
  285.     result=API_E3(&Request,&Reply);
  286.  
  287.     if (result!=0) {
  288.         if (result!=0xFC) PrintError(result);
  289.         return (0l);
  290.     }
  291.     else
  292.     {
  293.         PServer.s[0]=Reply.PropertyValue[0];
  294.         PServer.s[1]=Reply.PropertyValue[1];
  295.         PServer.s[2]=Reply.PropertyValue[2];
  296.         PServer.s[3]=Reply.PropertyValue[3];
  297.         return (PServer.l);
  298.     }
  299. }
  300.  
  301. void GetPrinterName(LONG PrintID, char *PrintName)
  302. {
  303.     struct getBindObjNameReq Request;
  304.     struct getBindObjNameRep Reply;
  305.     int    result;
  306.  
  307.     zap(Request); size(Request);
  308.     zap(Reply);   size(Reply);
  309.     Request.Function=0x36; // p 153
  310.     Request.ObjectID=PrintID;
  311.  
  312.     result=API_E3(&Request,&Reply);
  313.  
  314.     if (result>0) {
  315.         PrintError(result);
  316.         strcpy(PrintName,"");
  317.     }
  318.     else {
  319.         strcpy(PrintName,Reply.ObjectName);
  320.     }
  321. }
  322.  
  323. void GetPrinterLoc(char *PrintName, char *Location)
  324. {
  325.     struct readPropValueReq Request;
  326.     struct readPropValueRep Reply;
  327.     int    result;
  328.  
  329.     zap(Request); size(Request);
  330.     zap(Reply);   size(Reply);
  331.     Request.Function=0x3D; // p160
  332.     Request.ObjectType=swapw(0x0007); // Queue Server
  333.     Request.ObjectNameLength=sizeof(Request.ObjectName);
  334.     strcpy(Request.ObjectName,PrintName);
  335.     Request.SegmentNumber=1;
  336.     Request.PropertyNameLength=14;
  337.     strcpy(Request.PropertyName,"IDENTIFICATION");
  338.  
  339.     result=API_E3(&Request,&Reply);
  340.  
  341.     if (result!=0)
  342.     {
  343.         PrintError(result);
  344.         strcpy(Location,"");
  345.     }
  346.     else strcpy(Location,Reply.PropertyValue);
  347. }
  348.  
  349. void GetPrintList()
  350. {
  351.     struct readQueueStatReq Request;
  352.     struct readQueueStatRep Reply;
  353.     int    result;
  354.  
  355.     int i;
  356.  
  357.     zap(Request); size(Request);
  358.     Request.Function=0x66; // p 184
  359.     for (i=0;i<QueueCount;i++)
  360.     {
  361.         zap(Reply);   size(Reply);
  362.         Request.ObjectID=QueueList[i].QueueID;
  363.         result=API_E3(&Request,&Reply);
  364.         if (result>0 && result!=0xD2)
  365.         {
  366.             PrintError(result);
  367.             return;
  368.         }
  369.         QueueList[i].NumOfJobs=Reply.NumberOfJobs;
  370.         QueueList[i].NumOfServers=Reply.NumberOfServers;
  371.         if (Reply.NumberOfServers>0)
  372.         {
  373.             QueueList[i].Ready=1;
  374.             QueueList[i].PrintID=Reply.ServerID[0];
  375.         }
  376.         else
  377.         {
  378.             QueueList[i].Ready=0;
  379.             Queue